package Newsblog;
//12.16牛客小白月赛
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/12/16 19:49
 */
public class GingersLargeGarland {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        long[]arr=new long[k];
        for (int i = 0; i < k; i++) {
            arr[i]=sc.nextLong();
        }
        if(k<=1){
            System.out.println("Ginger666");
            return;
        }
        Arrays.sort(arr);
        int x=n/3;
        for (int i = 0; i < x; i++) {
            System.out.print(arr[0]+" "+arr[1]+" "+arr[0]+" ");
        }
        long sum= (long) x *(arr[0]+arr[0]+arr[1]);
        if(n%3==2){
            sum= sum +(long)(arr[1]+arr[0]);
            System.out.println(arr[0]+" "+arr[1]+" ");
        }
        if(n%3==1){
            sum= sum+ (long) arr[1];

        }

        System.out.println(sum);
    }
}
